package com.iov.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.iov.order.domain.TbOrder;
import com.iov.order.service.ITbOrderService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2023-11-23
 */
@RestController
@RequestMapping("/orderinfo")
public class TbOrderController extends BaseController
{
    @Autowired
    private ITbOrderService tbOrderService;

    /**
     * 查询订单列表
     */
    @RequiresPermissions("order:orderinfo:list")
    @GetMapping("/list")
    public TableDataInfo list(TbOrder tbOrder)
    {
        startPage();
        List<TbOrder> list = tbOrderService.selectTbOrderList(tbOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("order:orderinfo:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbOrder tbOrder)
    {
        List<TbOrder> list = tbOrderService.selectTbOrderList(tbOrder);
        ExcelUtil<TbOrder> util = new ExcelUtil<TbOrder>(TbOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("order:orderinfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbOrderService.selectTbOrderById(id));
    }

    /**
     * 新增订单
     */
    @RequiresPermissions("order:orderinfo:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbOrder tbOrder)
    {
        return toAjax(tbOrderService.insertTbOrder(tbOrder));
    }

    /**
     * 修改订单
     */
    @RequiresPermissions("order:orderinfo:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbOrder tbOrder)
    {
        return toAjax(tbOrderService.updateTbOrder(tbOrder));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("order:orderinfo:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbOrderService.deleteTbOrderByIds(ids));
    }

//    @RequiresPermissions("order:orderinfo:alipay")
//    @RequestMapping("/alipay")
//    public class AlipayDemo {
//        private String serverUrl = "https://openapi.alipaydev.com/gateway.do";
//        private String appId = "9021000131640899"; //请换成你自己的
//        private String privateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCDi3tHck0Wyu+SW5ABbfkpQ6UXOvw1AlgDLejXLouDZkj5Ho47aszyw7UINoNSV2SX70yrQ5iFisQEVrVFQu1+xMZ30H19s9BRQAzGW7U3RENxZ3wxEQflYVWMTh1GQzhq67Xwi7i72JSWHjtT3XXOKFxMBv6OnjLMCAk5vokKRxSXxD92JoemVkR0sn7nKyejrAWISL03tnuyxhkhSkMjFdcDA9RRJfhMGuW582ZtEYnFvnusAFs8eqkdlYP+bFlXN4YA/Q49o8Q1HT1u+XLci6dyxY3//AC7+h8CQeH4pfomBESKkWgdNSLTlPMQaCCJELNGkRSLgK56PLgKppgXAgMBAAECggEAbkda3HTIh9ktqwcz3N7zSVK6bpU2psIGQvQUBYGx2EDB4IdrOgi5NLQ5al85DKjTXkRxhAqxLRM+bVy7rwsCy4nv0LZq3h0HAXauvwRXEbQazlGxXfknI3fMHknGZQcpnwloh/a6slBJkOhbWF2Ky4AukFY0xh99+mqqQUyo2oG0iwB21emdaJHornmUDZpkdrvm6WvIs11+4R54x44sTz+YykwTrBa2Nn2UxcETdcfliuB4AFhxPs1dEvoeBt92lQS0Vrv5sx1PdIW4b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I+R6OO2rM8sO1CDaDUldkl+9Mq0OYhYrEBFa1RULtfsTGd9B9fbPQUUAMxlu1N0RDcWd8MREH5WFVjE4dRkM4auu18Iu4u9iUlh47U911zihcTAb+jp4yzAgJOb6JCkcUl8Q/diaHplZEdLJ+5ysno6wFiEi9N7Z7ssYZIUpDIxXXAwPUUSX4TBrlufNmbRGJxb57rABbPHqpHZWD/mxZVzeGAP0OPaPENR09bvly3IuncsWN//wAu/ofAkHh+KX6JgREipFoHTUi05TzEGggiRCzRpEUi4Cuejy4CqaYFwIDAQAB"; //请换成你自己的
//
//        //创建订单接口
//        @ResponseBody
//        @GetMapping("/create")
//        public String create() {
//            //创建连接
//            AlipayClient alipayClient = new DefaultAlipayClient(serverUrl, appId, privateKey, "json", "UTF-8", alipayPublicKey, "RSA2");
//            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
//
//            //订单信息
//            JSONObject bizContent = new JSONObject();
//            bizContent.put("out_trade_no", "202300012617623");
//            bizContent.put("total_amount", 100.00);
//            bizContent.put("subject", "付款");
//            bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
//
//            request.setBizContent(bizContent.toString());
//
//            AlipayTradePagePayResponse response = null;
//            try {
//                response = alipayClient.pageExecute(request);
//            } catch (AlipayApiException e) {
//                e.printStackTrace();
//            }
//            if (response.isSuccess()) {
//                //成功
//                return response.getBody();
//            } else {
//                //失败
//                return "调用失败";
//            }
//        }
//    }
}
